// 获取cookie、
export function getCookie (name) {
  // eslint-disable-next-line one-var
  var arr, reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)')
  // eslint-disable-next-line no-cond-assign
  if (arr = document.cookie.match(reg)) {
    return (arr[2])
  } else {
    return null
  }
}

// 设置cookie,增加到vue实例方便全局调用
export function setCookie (cData, exdays) {
  var exdate = new Date() // 获取时间
  exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays) // 保存的天数
  // 字符串拼接cookie
  window.document.cookie = cData + ';path=/;expires=' + exdate.toGMTString()
//   window.document.cookie = "userName" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();
//   window.document.cookie = "userPwd" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();
};

// 删除cookie
export function delCookie (name) {
  var exp = new Date()
  exp.setTime(exp.getTime() - 1)
  var cval = getCookie(name)
  if (cval != null) {
    document.cookie = name + '=' + cval + ';expires=' + exp.toGMTString()
  }
}
// 清除cookie
export function clearCookie () {
  this.setCookie('', -1)// 修改2值都为空，天数为负1天就好了
}
